package com.java.util;

import com.java.util.pojo.User;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 基本类型分组
 */
public class IntegerMap {


    public static void main(String[] args) {
        List<Integer> integers = Arrays.asList(1, 1, 2, 2, 3, 4, 5);

        // 使用Stream API进行分组和计数
        Map<Integer, Long> countMap = integers.stream()
                .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

        // 打印结果
        countMap.forEach((key, value) -> System.out.println(key + ": " + value));
    }
}
